package com.example.chatzsyproject.adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.chatzsyproject.R;
import com.example.chatzsyproject.app.MyApplication;
import com.example.chatzsyproject.model.FriendModel;
import com.example.chatzsyproject.view.AZListView.azlist.AZBaseAdapter;
import com.example.chatzsyproject.view.AZListView.azlist.AZItemEntity;

import java.util.List;

public class ContactsAdapter extends AZBaseAdapter<FriendModel, ContactsAdapter.ItemHolder> {

    public ContactsAdapter(List<AZItemEntity<FriendModel>> dataList) {
        super(dataList);
    }

    private OnItemClickListeren onItemClickListeren;

    public void setOnItemClickListeren(OnItemClickListeren onItemClickListeren) {
        this.onItemClickListeren = onItemClickListeren;
    }

    @Override
    public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ItemHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_contacts, parent, false));
    }

    @Override
    public void onBindViewHolder(ItemHolder holder, final int position) {
        Glide.with(MyApplication.getInstance()).load(mDataList.get(position).getValue().getHead_image()).into(holder.im_head);
        holder.mTextName.setText(mDataList.get(position).getValue().getUser_name());

        holder.item_re.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onItemClickListeren != null){
                    onItemClickListeren.onClick(position);
                }
            }
        });
    }

    static class ItemHolder extends RecyclerView.ViewHolder {

        TextView mTextName;
        ImageView im_head;
        RelativeLayout item_re;

        ItemHolder(View itemView) {
            super(itemView);
            mTextName = itemView.findViewById(R.id.text_item_name);
            im_head = itemView.findViewById(R.id.im_head);
            item_re = itemView.findViewById(R.id.item_re);
        }
    }

    public interface OnItemClickListeren{
        void onClick(int position);
    }
}
